package worldinruin.gui.imp.gameview;

import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JLabel;

import worldinruin.controllers.ControlFactory;
import worldinruin.controllers.ControlFactory.Controllers;
import worldinruin.resources.Components;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class MessagePanel extends javax.swing.JPanel {
	private JLabel textMessageLabel;
	private JButton endTurnButton;
	private String text;
	
	private Action listener;

	/**
	 * Creates a message panel.
	 */
	public MessagePanel() {
		super();
		initGUI();
		initListener();
	}
	
	/**
	 * Creates a message panel with given text.
	 * @param text Text to display.
	 */
	public MessagePanel(String text){
		this();
		updateMessage(text);
	}
	
	/**
	 * Initializes listeners to components.
	 */
	private void initListener() {
		listener = ControlFactory.getControl(Controllers.GAME_CONTROLLER);
		endTurnButton.addActionListener(listener);
		listener.putValue(Components.endTurnButton, endTurnButton);
	}
	
	/**
	 * Updates the messagepanel with a new message from the system.
	 * @param text A message string.
	 */
	public void updateMessage(String text) {
		this.text = text;
		textMessageLabel.setText("Message: " + text);
	}
	
	/**
	 * Initializes the GUI.
	 */
	private void initGUI() {
		try {
			setPreferredSize(new Dimension(400, 300));
			FlowLayout thisLayout = new FlowLayout();
			this.setLayout(thisLayout);
			{
				textMessageLabel = new JLabel();
				this.add(textMessageLabel);
				textMessageLabel.setText("Message: " + text);
				textMessageLabel.setPreferredSize(new java.awt.Dimension(329, 16));
			}
			{
				endTurnButton = new JButton();
				this.add(endTurnButton);
				endTurnButton.setText("End turn");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
